oa12 <- oa.design(nlevels=c(2,2,6))
#### Examples for extractor function
## subsetting to half the runs drops all attributes per default
oa12[1:6,]
## keep the attributes (usually not reasonable, but ...)
oa12[1:6, drop.attr=FALSE]
## reshuffling a design
## (re-)randomize
oa12[sample(12),]
## add repeated measurements
oa12[rep(1:12,each=3),]
## add a proper replication
## (does not work for blocked designs)
oa12[c(sample(12),sample(12)),]
## subsetting and rbinding to loose also contrasts of factors
str(rbind(oa12[1:2,],oa12[3:12]))
## keeping all non-design-related attributes like the contrasts
str(undesign(oa12))
#### Examples for plotting designs
## plotting a design without response (uses function mosaic from package vcd)
plot(oa12)
## equivalent to mosaic(~A+B+C, oa12)
## alternative order:
mosaic(~C+A+B, oa12)
## using the select function: the plots show that the projection for factors
## C, D and E (columns 3, 14 and 15 of the array) is a full factorial,
## while A, D and E does (columns 1, 14, and 15 of the array) do not occur in
## all combinations
plot(oa.design(L24.2.13.3.1.4.1,nlevels=c(2,2,2,3,4)),select=c("E","D","A"))
plot(oa.design(L24.2.13.3.1.4.1,nlevels=c(2,2,2,3,4)),select=c("E","D","C"))
## plotting a design with response
y=rnorm(12)
plot(oa12, y)
## plot design with a response included
oa12.r <- add.response(oa12,y)
plot(oa12.r)
## plotting a numeric design (with or without response,
## does not make statistical sense here, for demo only)
noa12 <- qua.design(oa12, quantitative="all")
plot(noa12, y, main="Scatter Plot Matrix")
#### Examples print and summary
## rename factors and relabel levels of first two factors
namen <- c(rep(list(c("current","new")),2),list(""))
names(namen) <- c("First.Factor", "Second.Factor", "Third.Factor")
factor.names(oa12) <- namen
oa12 ### printed with the print method!
## add a few variables to oa12
responses <- cbind(temp=sample(23:34),y1=rexp(12),y2=runif(12))
oa12 <- add.response(oa12, responses)
response.names(oa12)
## temp (for temperature) is not meant to be a response
## --> drop it from responselist but not from data
response.names(oa12) <- c("y1","y2")
## print design
oa12
## look at design-specific summary
summary(oa12)
## look at data frame style summary instead
summary.data.frame(oa12)
## aggregation examples
plan <- oa.design(nlevels=c(2,6,2), replications=2, repeat.only=TRUE)
y <- rnorm(24)
z <- rexp(24)
plan <- add.response(plan, cbind(y=y,z=z))
plan <- reptowide(plan)
plan.mean <- aggregate(plan)
plan.mean
aggregate(plan, response="z")
aggregate(plan, FUN=sd)
aggregate(plan, FUN = function(obj) max(obj) - min(obj), postfix="range")
## several aggregates: add standard deviations to plan with means
plan.mean.sd <- aggregate(plan.mean, FUN=sd)
plan.mean.sd
response.names(plan.mean.sd)
## change response.names element of design.info back to y.mean and z.mean
## may be needed for automatic analysis routines that have not been
## created yet
plan.mean.sd <- aggregate(plan.mean.sd, FUN=mean)
plan.mean.sd
response.names(plan.mean.sd)
Run the code above in your browser using DataLab